package ui.activity.mine;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Button;

import com.jakewharton.rxbinding.view.RxView;

import net.ck.hzq.R;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import base.BaseAct;
import butterknife.BindView;
import event.NetErrorEvent;
import ui.activity.mine.biz.ComplaintBiz;
import ui.activity.mine.component.DaggerComplaintComponent;
import ui.activity.mine.contract.ComplaintContract;
import ui.activity.mine.module.ComplaintModule;
import ui.activity.mine.presenter.ComplaintPresenter;
import widget.ClearEditText;


/**
 * 投诉建议
 * Created by chenjian on 2017/8/4.
 */

public class ComplaintAct extends BaseAct implements ComplaintContract.View {


    @Inject
    ComplaintPresenter presenter;
    @Inject
    ComplaintBiz biz;

    @BindView(R.id.complaint_edit)
    ClearEditText input;
    @BindView(R.id.complaint_but)
    Button submit;


    private SharedPreferences sp;

    @Override
    protected void setRoot() {
//        setTitleBar(R.color.colorBlue);
        setContentView(R.layout.activity_complaint);
    }

    @Override
    protected void setup() {
        DaggerComplaintComponent.builder().complaintModule(new ComplaintModule(this)).build().inject(this);
        setToolBar(getResources().getString(R.string.complaintproposal), "");
        presenter.setBiz(biz);
    }


    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        sp = getSharedPreferences("ToBuy", Context.MODE_PRIVATE);
        RxView.clicks(submit)
                .compose(this.<Void>bindToLifecycle())
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(Void -> presenter.setInfo(sp.getString("id", "0"), input.getText().toString().trim()));
    }

    @Override
    public void onNetErrorEvent(NetErrorEvent event) {
        super.onNetErrorEvent(event);
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        biz.onDestory();
    }

}
